package com.xpgk.mvc.statistic.loseSizeList;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bouncycastle.crypto.tls.MACAlgorithm;

import com.jfinal.aop.Before;
import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.xpgk.annotation.Service;
import com.xpgk.constant.ConstantRender;
import com.xpgk.dto.RenderBean;
import com.xpgk.mvc.base.BaseService;
import com.xpgk.mvc.binShopService.ServicePartSize;
import com.xpgk.mvc.bloseWeight.DelWeiTarget;
import com.xpgk.mvc.statistic.dailyNursing.DailyNursingStatisticSQL;
import com.xpgk.mvc.statistic.loseWeightList.LoseWeightListSQL;
import com.xpgk.mvc.statistic.spropagandaTraining.SpropagandaTrainingSQL;
import com.xpgk.tools.ToolDateTime;


@Service(name = LoseSizeListService.serviceName)
public class LoseSizeListService extends BaseService{

	@SuppressWarnings("unused")
	private static final Log log = Log.getLog(LoseSizeListService.class);
	public static final String serviceName = "loseSizeListService";
	
	
	/*
	 * 顾客数据查询
	 */
	
	public List<Record> customerDataQuey(String organIdsEmployee,String arrivedMinDate ,String hybh,String customerName,String customerPhone) throws Exception{
		String sql = LoseSizeListSQL.losesizelist_splitPage;
//		String sqlMy = getSqlMy(LoseSizeListSQL.losesizelist_querysizetype);
		String sqlType = getSqlMy(LoseSizeListSQL.losesizelist_customerquerylosesize);
		String sqlTypedangqian = getSqlMy(LoseSizeListSQL.losesizelist_customerquerylosesizedangqian);
		
		Map<String, Object> queryParam = new HashMap<String, Object>();
	    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");  
	    Date date = sdf.parse(arrivedMinDate);
	    Map<String, Date> monthDate = ToolDateTime.getMonthDate(date);
	    queryParam.put("organIdsEmployee", organIdsEmployee);
	    queryParam.put("arrivedMinDate",sdf.format(monthDate.get("start")));
	    queryParam.put("arrivedMaxDate",sdf.format(monthDate.get("end")));
	    queryParam.put("hybh", hybh);
	    queryParam.put("customerName", customerName);
	    queryParam.put("customerPhone", customerPhone);
		List<Record> result = find(sql,queryParam);

//		List<Record> parttype = Db.find(sqlMy);
		
		for(Record r : result){
			String customerids = r.get("ids").toString();
			ServicePartSize sc = ServicePartSize.dao.findFirst(sqlType,customerids);
		if(sc!=null){
			r.set("qssc", sc.getStr(ServicePartSize.column_qs))
			.set("qzsc", sc.getStr(ServicePartSize.column_qz))
			.set("qxsc", sc.getStr(ServicePartSize.column_qx))
			.set("zbsc", sc.getStr(ServicePartSize.column_zb))
			.set("ybsc", sc.getStr(ServicePartSize.column_yb))
			.set("zdtsc", sc.getStr(ServicePartSize.column_zdt))
			.set("zxtsc", sc.getStr(ServicePartSize.column_zxt))
			.set("ydtsc", sc.getStr(ServicePartSize.column_ydt))
			.set("yxtsc", sc.getStr(ServicePartSize.column_yxt));
		}
				
				ServicePartSize dq = ServicePartSize.dao.findFirst(sqlTypedangqian,customerids);
				if(dq!=null){
					r.set("qsdq", dq.getStr(ServicePartSize.column_qs))
					.set("qzdq", dq.getStr(ServicePartSize.column_qz))
					.set("qxdq", dq.getStr(ServicePartSize.column_qx))
					.set("zbdq", dq.getStr(ServicePartSize.column_zb))
					.set("ybdq", dq.getStr(ServicePartSize.column_yb))
					.set("zdtdq", dq.getStr(ServicePartSize.column_zdt))
					.set("zxtdq", dq.getStr(ServicePartSize.column_zxt))
					.set("ydtdq", dq.getStr(ServicePartSize.column_ydt))
					.set("yxtdq", dq.getStr(ServicePartSize.column_yxt));
				}
				if(sc!=null&&dq!=null){
					r.set("qslj", Float.parseFloat(dq.getStr(ServicePartSize.column_qs))-Float.parseFloat(sc.getStr(ServicePartSize.column_qs)))
					.set("qzlj",  Float.parseFloat(dq.getStr(ServicePartSize.column_qz))-Float.parseFloat(sc.getStr(ServicePartSize.column_qz)))
					.set("qxlj",  Float.parseFloat(dq.getStr(ServicePartSize.column_qx))-Float.parseFloat(sc.getStr(ServicePartSize.column_qx)))
					.set("zblj",  Float.parseFloat(dq.getStr(ServicePartSize.column_zb))-Float.parseFloat(sc.getStr(ServicePartSize.column_zb)))
					.set("yblj",  Float.parseFloat(dq.getStr(ServicePartSize.column_yb))-Float.parseFloat(sc.getStr(ServicePartSize.column_yb)))
					.set("zdtlj",  Float.parseFloat(dq.getStr(ServicePartSize.column_zdt))-Float.parseFloat(sc.getStr(ServicePartSize.column_zdt)))
					.set("zxtlj", Float.parseFloat(dq.getStr(ServicePartSize.column_zxt))-Float.parseFloat(sc.getStr(ServicePartSize.column_zxt)))
					.set("ydtlj",  Float.parseFloat(dq.getStr(ServicePartSize.column_ydt))-Float.parseFloat(sc.getStr(ServicePartSize.column_ydt)))
					.set("yxtlj",  Float.parseFloat(dq.getStr(ServicePartSize.column_yxt))-Float.parseFloat(sc.getStr(ServicePartSize.column_yxt)));
				}
				
				
			
		}	
		return result;
	}
}
